Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 4 - Geometric Operations / Using Geometric Operations


Determining Whether Two Shapes Touch

QuickDraw GX provides three functions to help you determine whether the areas of two shapes touch--that is, whether they intersect, even at a single point.

This section shows examples of using the GXTouchesShape function. The sample function in Listing 4-10 defines a rectangle and a circular path shape to use for these examples.

Listing 4-10 Creating a rectangle and a circular path shape

void CreateBoxedCircle(void)
{
   gxShape aLargeCircle;

   static gxRectangle largeBounds = {ff(50), ff(50), 
                                     ff(150), ff(150)};
   
   static long largeCircleGeometry[] = {1,/* number of contours */
                                        4,/* number of points */
                                        0xF0000000, /* 1111 ... */
                                        ff(50), ff(50),  /* off */
                                        ff(150), ff(50), /* off */
                                        ff(150), ff(150),/* off */
                                        ff(50), ff(150)};/* off */


   aLargeCircle = GXNewPaths((gxPaths *) largeCircleGeometry);
   GXSetShapeFill(aLargeCircle, gxClosedFrameFill);

   GXDrawRectangle(&largeBounds, gxClosedFrameFill);
   GXDrawShape(aLargeCircle);
   GXDisposeShape(aLargeCircle);
}
The result of this function is shown in Figure 4-46.

Figure 4-46 A rectangle containing a circular path

You can call the GXTouchesBoundsShape function to test whether the rectangle and the path shape defined in Listing 4-10 touch:

GXTouchesBoundsShape(&largeBounds, aLargeCircle)
This function call returns true; the area of the rectangle does intersect the area of the path.

When calculating whether a rectangle and a shape intersect, the GXTouchesBoundsShape function assumes that the rectangle has an even-odd shape fill. The following code defines another, smaller, path shape to test for intersection with the rectangle defined in Listing 4-10:

gxShape aSmallCircle;

static long smallCircleGeometry[] = {1, /* number of contours */
                                     4, /* number of points */
                                     0xF0000000, 
                                     ff(65), ff(65),  /* off */
                                     ff(135), ff(65), /* off */
                                     ff(135), ff(135),/* off */
                                     ff(65), ff(135)};/* off */
aSmallCircle = GXNewPaths((gxPaths *) smallCircleGeometry);
GXSetShapeFill(aSmallCircle, gxClosedFrameFill);
The call

GXTouchesBoundsShape(&largeBounds, aSmallCircle);
returns true because the smaller path shape touches the area contained by the rectangle, as shown in Figure 4-47.

Figure 4-47 A rectangle that touches a circular path shape

The GXTouchesBoundsShape function returns true even if the rectangle and the path shape share only an edge or even a single point. For example, if you move the small circle to the right by a distance of 85.0 points by calling

GXMoveShape(aSmallCircle, ff(85), 0);
as depicted in Figure 4-48, then the call

GXTouchesBoundsShape(&largeBounds, aSmallCircle)
still returns true.

Figure 4-48 A rectangle and a circular path touching at a single point

The GXTouchesShape function works similarly to the GXTouchesBoundsShape function, but it determines whether any two shapes intersect.

As an example, if you give the path shapes defined earlier in this section the even-odd shape fill by calling

GXSetShapeFill(aLargeCircle, gxEvenOddFill);
GXSetShapeFill(aSmallCircle, gxEvenOddFill);
then the call

GXContainsShape(aLargeCircle, aSmallCircle)
returns true; the small path intersects the area contained in the large path, as shown in Figure 4-49.

Figure 4-49 A large circular path shape touching a smaller circular path shape

For information about the GXTouchesRectanglePoint function, see page 4-96. For more information about the GXTouchesBoundsShape function and the GXTouchesShape function, see page 4-97 and page 4-98, respectively.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help